package com.wm.task.dao;

import com.wm.task.util.DbHelper;
import com.wm.task.vo.Movie;
import com.wm.task.vo.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class AdminDAO {
    private List<User> userList;

    public List<User> userList() {
        userList = new ArrayList<>();
        String sql = "SELECT * FROM user";
        Connection connection = DbHelper.getDate();
        try {
            PreparedStatement ps = connection.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                userList.add(new User(rs.getInt("id"), rs.getString("phone_num"),
                        rs.getString("pass"), rs.getString("name"),
                        rs.getTime("time"), rs.getString("secret_question"),
                        rs.getString("secret_answer")));
            }
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("列表问题");
        } finally {
            DbHelper.close(connection);
        }
        return userList;
    }

    public void userDelete(Integer id) {
        String sql = "DELETE FROM user WHERE id = ?;";
        DbHelper.update(sql, id);

    }
}
